#include <iostream>
using namespace std;

long power[32];
int main(){
	int a,b,d;//a,b<=2^30-1 ,1<d<=10
	int sum;
	cin>>a>>b>>d;
	sum = a+b;
	if( sum==0 ){
		cout<<0;
		return 0;
	} 
	power[0] = 1;
	for( int i=1; i<32; ++i ) power[i] = power[i-1]*d;
	int i= 0;
	for( ; ; ++i ){
		if( sum>=power[i]&&sum<power[i+1] ) break;
	}
	for( ; i>=0; --i ){
		cout<< sum/power[i];
		sum = sum%power[i];
	}
	return 0;
}
